<%--
 *  File:   UsrLoginMgmt.jsp
 *  Desc:	UsrLoginMgmt
 *
 *  Date		         Author		      Changes
 *  2006-11-16	  tracyliu		  Created
 *
 *  Copyright (C) 2000 - 2005 Oval Technologies, Inc.
 *  All rights reserved.
 *
 *  This software is the confidential and proprietary information of Oval
 *  Technologies, Inc. ("Confidential Information").  You shall not
 *  disclose such Confidential Information and shall use it only in
 *  accordance with the terms of the license agreement you entered into
 *  with Oval.
--%>
<%
  //init param
  String privilegeCode = "ALL";
  String strTableName = "";
  String strModuleName = "COM";
	String contextPath = request.getContextPath();
%>
<%@ include file="/inc/CommonHeader.inc" %>
<%@ include file="/inc/OvalLocationDefault.inc" %>

<html>
<head>
<title>UsrLoginMgmt</title>
<PageFlow:CheckPageFlow pageName="p_usrloginmgmt"/>
<%@ include file="/inc/CatchError.inc" %>
<%@ include file="/inc/SumDiv.inc" %>
<%
  Vector exceptlist = (Vector)pageContext.getAttribute("exceptlist");
  if(exceptlist == null) exceptlist = new Vector();
    
  HashMap userhash = (HashMap)session.getAttribute("userinfo");
%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="<%=contextPath%>/css/<%= strLanguageCode %>/main.css" type="text/css">
<script language="JavaScript" src="<%=contextPath%>/css/<%= strLanguageCode %>/script.js"></script>
<script language="JavaScript" src="<%=contextPath%>/js/ScriptLib.js"></script>
<script language="JavaScript" src="<%=contextPath%>/js/SummaryDivision.js"></script>
<script language="JavaScript">
<%--  put your custom script here   --%>
function page_summary(actionvalue,orderbyname)
{
  var editform = summaryPrepare(cform,actionvalue,orderbyname);
  if(!editform) return;
  editform.action = "UsrLoginMgmt.jsp?<%= OvalTools.randomURL() %>&getusr=true";
  editform.target = "_self";
  isRunning = true;
  editform.submit();
}
function clickRow(obj,idx)
{
  var cform = document.cform;
<%--  cform.radiorow[idx].checked=true;--%>
  cform.userid.value = eval('obj.all.userid'+idx).value;
}
function page_go()
{
  cform.action = "UsrLoginMgmt.jsp?<%= OvalTools.randomURL() %>";
  cform.target = "_self";
  isRunning = true;
  cform.submit();
}
function page_bgorgselect(rootpath,params,name)
{
  if (document.all.item("bgorgbutton").disabled == true)
  {
     return;
  }
  else
  {
   var status="height=380, width=600,top=100,left=100,toolbar=n0, menubar=no, scrollbars=yes, resizable=no, location=no, status=no";
   var url="OrgPopSummaryForLogin.jsp?<%= OvalTools.randomURL() %>&selecttype=bgorg";

   if(popwindow!=null)
      popwindow.close();
   popwindow=window.open(url, "newwindow", status);
   }
}
function page_setBgOrg(orgid,orgcode,orgname)
{
  cform.bgshortname.value=orgname;
  cform.bgorgid.value=orgid;
  cform.bgorgcode.value=orgcode;
  cform.shortname.value="";
  cform.orgid.value="";
  cform.orgcode.value="";
  cform.booksetid.value="";
  if(popwindow!=null)
    popwindow.close();
    page_go();
}

function reloadbgorg()
{
   if (document.cform.bgorgcode.value == "")
   {
          document.cform.bgorgid.value = null;
          document.cform.bgshortname.value = "";
          return;
   }
    var  datahandler = new  DataHandler() ;
    datahandler.add_params("orgcode" , document.cform.bgorgcode.value,"string") ;
    datahandler.getResult("shortname" ,"document.cform.bgshortname") ;
    datahandler.getResult("orgid","document.cform.bgorgid");
    datahandler.add_job("j_getorg") ;
    datahandler.add_function("page_go()");
    datahandler.runDataHandler ();
}
function reloadorg()
{
   if (document.cform.orgcode.value == "")
   {
          document.cform.orgid.value = null;
          document.cform.shortname.value = "";
          return;
   }
    var  datahandler = new  DataHandler() ;
    datahandler.add_params("orgcode" , document.cform.orgcode.value,"string") ;
    datahandler.getResult("shortname" ,"document.cform.shortname") ;
    datahandler.getResult("orgid","document.cform.orgid");
    datahandler.add_job("j_getorg") ;
    datahandler.add_function("page_go()");
    datahandler.runDataHandler ();
}
function page_orgselect(rootpath,params,name)
{
   if (document.all.item("orgbutton").disabled == true)
   {
      return;
   }
   else{
   var status="height=380, width=600,top=100,left=100,toolbar=n0, menubar=no, scrollbars=yes, resizable=no, location=no, status=no";
   var url='OrgPopSummaryForLogin.jsp?<%= OvalTools.randomURL() %>&selecttype=org&bgorgid='+document.cform.bgorgid.value+'&booksetid='+document.cform.booksetid.value;

   if(popwindow!=null)
      popwindow.close();
   popwindow=window.open(url, "newwindow", status);
   }
}
function page_setOrg(orgid,orgcode,orgname)
{
  cform.shortname.value=orgname;
  cform.orgid.value=orgid;
  cform.orgcode.value=orgcode;
  if(popwindow!=null)
    popwindow.close();
    page_go();
}
function page_usrselect(rootpath,params,name)
{
   var winstatus="height=380, width=600,top=100,left=100,toolbar=n0, menubar=no, scrollbars=yes, resizable=no, location=no, status=no";
   var url='UsrPopSummary.jsp?<%= OvalTools.randomURL() %>&bgorgid='+document.cform.bgorgid.value+'&booksetid='+document.cform.booksetid.value+'&orgid='+document.cform.orgid.value+'&status='+document.cform.hiddenstatus.value;

   if(popwindow!=null)
      popwindow.close();
   popwindow=window.open(url, "newwindow", winstatus);
}
function page_setUsr(userid,username,fullname,shortname,email,statusname)
{

   cform.newuserid.value=userid;
   cform.newusername.value=username;
   cform.newfullname.value=fullname;
   cform.newshortname.value=shortname;
   cform.newemail.value=email;
   cform.newstatusname.value=statusname;
    if(popwindow!=null)
    popwindow.close();
}
function page_add()
{
    var flag = 1;

    for (var i = 0; i < <%=JspHelper.filterNull( exceptlist.size())%>; i++)
    {
      if (eval("document.cform.newuserid" + i).value == document.cform.newuserid.value )
      {
          flag = 0;
          alert("<%= message.getMessageDesc("CAN_NOT_ADD_SAME_USER") %>");;
      }
    }

      if (flag == 1)
      {
        if(!checkALLElems(document.getElementById("newdetail"))) return;

          cform.actionname.value = "add";
          cform.target = "_self";
          isRunning = true;
          cform.submit();
      }
}
function page_delete()
{
    if(isNullChecked(cform.deleteids))
    {
        alert("<%= message.getMessageDesc("MUST_SELECT_ONE_RECORD_TO_DEL") %>");
        return;
    }
    if(!confirm("<%= message.getMessageDesc("ARE_YOU_SURE_DEL") %>")) return;
    cform.actionname.value = "delete";
    cform.target = "_self";
    isRunning = true;
    cform.submit();
}
function page_init()
{
     if (document.cform.orgtype.value == "other")
     {
            document.all.item("bgorgbutton").disabled = true;
            document.all.item("orgbutton").disabled = true;
     }
     else if (document.cform.orgtype.value == "bgorg")
     {
             document.all.item("bgorgbutton").disabled = true;
     }
     else
     {
             document.all.item("bgorgbutton").disabled = false;
             document.all.item("orgbutton").disabled = false;
     }
}
function page_execute()
{
    cform.actionname.value = "execute";
    cform.target = "_self";
    isRunning = true;
    cform.submit();
}
</script>
</head>

<body style="overflow: auto;">
<form name="cform" method="post" action="<%=contextPath%>/Dispatcher">
    <input type="hidden" name="pagename" value="p_usrloginmgmt">
    <input type="hidden" name="actionname">
    <input type="hidden" name="numrows" value="<%=JspHelper.filterNull( exceptlist.size())%>">
    <input type="hidden" name="orgtype" value="<%=JspHelper.filterNull( pageContext.getAttribute("orgtype"))%>">
    <input type="hidden" name="hiddenstatus" value="<%=JspHelper.filterNull( pageContext.getAttribute("status"))%>">

<%--  page location   --%>
    <%@ include file="/inc/PageLocation.inc" %>
    <%
        String strChecked1 = "";
        String strChecked2 = "";
        boolean bgorgSelect = true;
        boolean booksetSelect = true;
        boolean orgSelect = true;
        Integer status = (Integer)pageContext.getAttribute("status");
        String orgtype = (String)pageContext.getAttribute("orgtype");

        if ((status == null) || (status.toString().equalsIgnoreCase("41")))
        {
            strChecked1 = "checked";
            strChecked2 = "";
        }
        else
        {
            strChecked1 = "";
            strChecked2 = "checked";
        }
        
        if (orgtype != null)
        {
            if (orgtype.equalsIgnoreCase("other"))
            {
                 bgorgSelect = true;
                 booksetSelect = true;
                 orgSelect = true;
            }
            else if (orgtype.equalsIgnoreCase("bgorg"))
            {
                bgorgSelect = true;
                booksetSelect = false;
                orgSelect = false;
            }
            else if (orgtype.equalsIgnoreCase("admin"))
            {
                bgorgSelect = false;
                booksetSelect = false;
                orgSelect = false;
            }
        }
    %>
    <table width="100%" cellspacing="0" border="0" cellpadding="0">
    <%--  search criteria  --%>
    <tr>
      <td><table width="100%" border="0" cellspacing="0">
      <tr><td>
      <%= label.getLabelName("L_BgOrg") + label.getLabelName("L_Colon")%>
      <custom:text property="bgorgcode" size="12" readonly = "<%= bgorgSelect%>" onchange="reloadbgorg()"  />
	  <custom:hidden property="bgorgid"/>
	  <a onclick="javascript:page_bgorgselect('../../','?<%= OvalTools.randomURL()%>&selecttype=bgorg')"><custom:button property="bgorgbutton" type="3"  label="L_Asterisk" imgsrc="flash.gif" border="0"/></a>
      <custom:text property="bgshortname" size="20" readonly = "true" />
      <%= label.getLabelName("L_BookSet") + label.getLabelName("L_Colon")%>
      <custom:select optionsName="allbooksets" disabled="false" optionValueKey="booksetid" optionInnerTextKey="booksetname" property="booksetid" defaultValue="-------" defaultValueCost="" onchange="page_go()" /></td></tr>
      <tr><td><%= label.getLabelName("L_Organizations") + label.getLabelName("L_Colon")%>
      <custom:text property="orgcode" size="12" readonly = "<%= orgSelect%>" onchange="reloadorg()"  />
	  <custom:hidden property="orgid"/>
	  <a onclick="javascript:page_orgselect('../../','?<%= OvalTools.randomURL()%>&selecttype=org')"><custom:button property="orgbutton" type="3" label="L_Asterisk" imgsrc="flash.gif" border="0"/></a>
      <custom:text property="shortname" size="20" readonly = "true" />
      <input type="radio" name="status" property="status" value="41" class="normalradio"<%=JspHelper.filterNull( strChecked1 )%>><%= label.getLabelName("L_ForbidLogin")%>
      <input type="radio" name="status" property="status" value="48" class="normalradio"<%=JspHelper.filterNull( strChecked2 )%>><%= label.getLabelName("L_AllowLogin")%>
      <a href="javascript:page_summary('search')"><img src="<%=contextPath%>/images/<%=JspHelper.filterNull( session.getAttribute("languagecode") )%>/go.gif" border="0" ></a></td>
    </tr></td></table></tr>
    <tr>
        <td>
          <table width="100%" border="1" cellpadding="0" bordercolorlight="#999999" bordercolordark="#FFFFFF" cellspacing="0" align="center">
          <%--  summary title columns  --%>
<%
    ArrayList titleTdArray = new ArrayList();

    titleTdArray.add(new TitleTD("100","L_UserName","username") );
    titleTdArray.add(new TitleTD("150","L_UserFullName","fullname") );
    titleTdArray.add(new TitleTD("200","L_OwnerOrg","shortname") );
    titleTdArray.add(new TitleTD("200","L_Email","email") );
    titleTdArray.add(new TitleTD("70","L_Status","statusname") );

%>
            <custom:titletr styleClass="deepblue-left" tdArray="<%=titleTdArray%>" />

<%--  summary data columns  --%>
 <%
     ArrayList detailTdArray = new ArrayList();

     detailTdArray.add(new WriteTD("username"));
     detailTdArray.add(new WriteTD("fullname"));
     detailTdArray.add(new WriteTD("shortname"));
     detailTdArray.add(new WriteTD("email"));
     detailTdArray.add(new WriteTD("statusname"));

	 //form hidden elements
     ArrayList hiddenArray = new ArrayList();
     hiddenArray.add(new HiddenInput("userid",true));
 %>
            <custom:iteratetr tdArray="<%=detailTdArray%>" hiddenArray="<%=hiddenArray%>"  dataSource="allusrs"/>
            <%@ include file="/inc/SummaryAction.inc" %>

          </table>

        </td>
      </tr>
      <tr><td>&nbsp;</td></tr>
      <tr><td><%= label.getLabelName("L_ExceptList") + label.getLabelName("L_Colon")%></td></tr>
      <tr>
          <td bgcolor=#000000 style="PADDING-BOTTOM: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; PADDING-TOP: 0px">
            <table bgcolor=#000000 border=0 cellpadding=0 cellspacing=0 width="100%">
              <tr>
                <td  bgcolor=#ffffff style="PADDING-BOTTOM: 3px; PADDING-LEFT: 3px; PADDING-RIGHT: 3px; PADDING-TOP: 3px">
                  <div id=div2 style="HEIGHT: 300px; OVERFLOW: auto">
                    <table border="1" cellspacing="0" bordercolorlight="#999999" bordercolordark="#FFFFFF" align="center" width="100%" cellpadding="1">

<%--    top function buttons    --%>

                    <tr>
                        <td colspan="20" class="td_right">
                          <a onclick="page_add();"><custom:button type="2" label="L_Add" imgsrc="add_btn.gif" border="0"/></a>
                          <%if(exceptlist.size()>0 ){%>
                          <a onclick="page_delete();"><custom:button type="2" label="L_Delete" imgsrc="delete_btn.gif" border="0"/></a>
                          <%}%>
                        </td>
                      </tr>


<%--  title columns  --%>
<%
    ArrayList titleTdArray1 = new ArrayList();
    titleTdArray1.add(new TD("30","&nbsp;"));
    titleTdArray1.add(new TitleTD("150","L_UserName") );
    titleTdArray1.add(new TitleTD("150","L_UserFullName"));
    titleTdArray1.add(new TitleTD("200","L_OwnerOrg"));
    titleTdArray1.add(new TitleTD("200","L_Email"));
    titleTdArray1.add(new TitleTD("70","L_Status"));
 %>
    <custom:titletr styleClass="td-listrom" tdArray="<%=titleTdArray1%>" />
<%
    boolean useridChecked = false;
%>
<%--  the old detail lines  --%>
 <span id="olddetail" >
                      <logic:iterate id="onerow" collection="<%= exceptlist %>" indexId="idx">
                      <%
                         HashMap hashTmp=(HashMap)pageContext.getAttribute("onerow");
                         if (hashTmp != null)
                         {
                             if (hashTmp.get("newuserid").toString().equalsIgnoreCase(userhash.get("userid").toString()))
                             {
                                      useridChecked = true;
                             }
                         }
                      %>
                      <tr>
                        <td width="30">
                          <custom:checkbox property="newuserid" name="onerow" changedName="deleteids" styleClass="normalradio" disabled="<%= useridChecked%>" />
                        </td>
                        <td><custom:write name="onerow" property="newusername" nbsp="true"/></td>
                        <td><custom:write name="onerow" property="newfullname" nbsp="true"/></td>
                        <td><custom:write name="onerow" property="newshortname" nbsp="true"/></td>
                        <td><custom:write name="onerow" property="newemail" nbsp="true"/></td>
                        <td><custom:write name="onerow" property="newstatusname" nbsp="true"/></td>
                      </tr>
                      <tr>
                        <td style="display:none">
                            <custom:hidden name="onerow" property="newuserid" colIndex="<%= idx %>"/>
                            <custom:hidden name="onerow" property="newusername" colIndex="<%= idx %>"/>
                            <custom:hidden name="onerow" property="newfullname" colIndex="<%= idx %>"/>
                            <custom:hidden name="onerow" property="newshortname" colIndex="<%= idx %>"/>
                            <custom:hidden name="onerow" property="newemail" colIndex="<%= idx %>"/>
                            <custom:hidden name="onerow" property="newstatusname" colIndex="<%= idx %>"/>
                         </td>
                      </tr>
                      <%
                          useridChecked = false;
                      %>
                      </logic:iterate>
</span>

<%--  the new detail line  --%>

<span id="newdetail" >
                      <tr >
                        <td>&nbsp;</td>
                        <td>
                          <custom:text name="newdetail" property="newusername" style="width:80%" command="notnull" module="COM" label="L_UserName" asterisk="true"  readonly="true" />
                          <a onclick="javascript:page_usrselect('../../','?<%= OvalTools.randomURL()%>')">
                          <custom:button type="3" label="L_Asterisk" imgsrc="flash.gif" border="0"/></a>
                        </td>
                        <td><custom:text name="newdetail" property="newfullname" style="width:100%" readonly="true" style="border:0"/></td>
                        <td><custom:text name="newdetail" property="newshortname"  style="width:100%" style="border:0" /></td>
                        <td><custom:text name="newdetail" property="newemail" readonly="true"style="width:100%" style="border:0" /></td>
                        <td><custom:text name="newdetail" property="newstatusname" readonly="true" size="8" style="border:0" /></td>
                     </tr>

                      <tr>
                        <td style="display:none">
                            <custom:hidden name="newdetail" property="newuserid" />
                        </td>
                      </tr>
</span>

                    </table>

                  </div>
                </td>
              </tr>

            </table>
          </td>
        </tr>
        <tr><td>
        <table width="100%" cellspacing="0" cellpadding="0">
              <tr>
                   <td colspan="20" class="td_center">
                          <a onclick="page_execute()"><custom:button type="1" label="L_Execute" imgsrc="finish.gif" border="0" style="width:60"/></a>
                  </td>
              </tr>
            </table>
        </td></tr>
      </table>
    </td>
  </tr>
    </table>
</form>
<script>
page_init();
</script>
</body>
</html>
